package com.tron.context;
//创建context包,创建redis和jwt的配置类

import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

@ConfigurationProperties(prefix = "redis-key" )
@Component
@Setter
public class RedisContext {
   //yml 配置 : redis-key: captcha:
   //验证前缀
   private String captcha = "back:captcha:";

   //yml 配置 : redis-key: jwt:
   //JWT令牌前缀
   private String jwt = "back:jwt:";

   private String  transactionHash = "transaction:hash:";

   private String  account = "account:address:";

   private String  orderPayKey = "create:order:pay:";

   private String  orderRecordKey = "create:order:record:";

   //可复用的账户
   private String  accountReuse = "account:reuse:";

   /**
   * 获取验证码的 key: 前缀 +uuid
   * @param uuid
   * @return
   */
   public String getCaptchaKey (String uuid) {
     return captcha + uuid ;
  }


   /**
   * 获取 jwt 的key: 前缀 +uuid
   * @param uuid
   * @return
   */
   public String getJWTKey (String uuid) {
     return jwt + uuid ;
  }

   /**
   * 获取交易的hash 的key: 前缀 +hash
   * @param hash
   * @return
   */
   public String getTransactionHashKey (String hash) {
     return transactionHash + hash ;
  }
   /**
   * 获取 jwt 的key: 前缀 + 私钥
   * @param key
   * @return
   */
   public String getCreateAddress (String key) {
     return account + key ;
  }


    /**
     * 获取 下订单的 key 这个在redis内含倒计时
     * @param address
     * @return
     */
   public String getOrderPayKey(String address){
       return orderPayKey+address;
   }

    /**
     * 获取 记录订单的 key 不含倒计时
     * @param address
     * @return
     */
   public String getRecordKey(String address){
       return orderRecordKey+address;
   }

    /**
     * 获取可服用的账户 KEY -- 从Redis获取
     * @param address 用户地址
     * @return 返回key
     */
   public String getAccountReuse(String address){
       return accountReuse+address;
   }
}
